<template>
  <common-list>
    <common-search slot="search" @search="handleQuery" @reset="resetQuery">
      <el-form
        @submit.native.prevent
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="50px"
      >
        <el-form-item label="IP地址" prop="ip">
          <common-input
            :maxlength="256"
            :verify="false"
            v-model="queryParams.ip"
            clearable
            @enter="handleQuery"
          />
        </el-form-item>
        <!-- <common-dept
          ref="commonDept"
          :currentParent="currentParent"
          @getDeptId="getDeptId"
          @getDeptList="getDeptList"
          @getLoading="getLoading"
        ></common-dept> -->
      </el-form>
    </common-search>

    <!-- <el-row slot="tools" :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          plain
          type="primary"
          icon="el-icon-s-check"
          :disabled="multiple"
          @click="HandleDistributeOrg"
          v-hasPermi="['apisecurity:apiinterface:distribution']"
          >分配组织
        </el-button>
      </el-col>
    </el-row> -->
    <common-table
      slot="content"
      v-loading="loading"
      :data="interfaceHttpsList"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        type="selection"
        width="55px"
        fixed="left"
        align="center"
      />
      <el-table-column
        label="IP地址"
        align="left"
        fixed="left"
        prop="ip"
        show-overflow-tooltip
      />
      <el-table-column
        label="端口号"
        align="left"
        prop="port"
        show-overflow-tooltip
      >
      </el-table-column>

      <el-table-column
        label="版本号"
        align="left"
        prop="version"
        show-overflow-tooltip
      />
      <el-table-column
        label="加密方式"
        align="left"
        prop="cipher"
        show-overflow-tooltip
      />
      <el-table-column
        label="当日访问量"
        align="left"
        prop="currentVisits"
        show-overflow-tooltip
      />
      <el-table-column
        label="创建时间"
        align="left"
        prop="createTime"
        show-overflow-tooltip
      />
      <el-table-column label="操作" align="left" width="80px" fixed="right">
        <template slot-scope="scope">
          <el-button type="text" @click="handleView(scope.row)"
            >详情
          </el-button>
        </template>
      </el-table-column>
    </common-table>
    <pagination
      slot="pagination"
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- <distribute-org
      ref="distributeOrg"
      :deptSelectArr="deptSelectArr"
      @toSubmit="toDistributeOrg"
    /> -->

    <http-details ref="httpDetails" />
  </common-list>
</template>

<script>
import {
  fetchHttpsList,
  updateDeptId,
} from "@/api/apisecurity/apiinterface/interface";
import DistributeOrg from "../../apisecurity/application/components/distributeOrg.vue";
import HttpDetails from "../apiinterface/components/httpsDetail.vue";
import { getSingleArray, getFullDept } from "@/utils/util";
import BaseList from "@/mixins/BaseList";
export default {
  name: "Https",
  mixins: [BaseList],
  components: { DistributeOrg, HttpDetails },
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ip: "",
        // deptIds: null,
      },
      loading: false,
      total: 0,
      multiple: true,
      deptListParams: [],
      deptSelectArr: [],
      ids: [],
      singleDeptList: [],
      currentParent: 3,
      interfaceHttpsList: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getLoading() {
      this.loading = true;
    },
    getCheckedDeptId(val) {
      this.form.deptId = val;
    },

    getList() {
      this.loading = true;
      fetchHttpsList(this.queryParams).then((res) => {
        this.loading = false;
        if (res && res.code === 200) {
          this.interfaceHttpsList = res.rows;
          this.total = res.total;
        } else {
          this.interfaceHttpsList = [];
          this.total = 0;
          this.handleListTips(res);
        }
      });
    },

    handleView(row) {
      this.$refs.httpDetails.show(row);
    },

    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    resetQuery() {
      this.queryParams = this.$options.data().queryParams;
      // this.$refs.commonDept.clearDept();
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.multiple = !selection.length;
    },

    HandleDistributeOrg() {
      // let includeDistributeOrg = this.interfaceHttpsList.find((v) => {
      //   return this.ids.includes(v.id) && v.deptId;
      // });
      // if (includeDistributeOrg) {
      //   this.$GlobalErrorConfirm("分配失败", "包含已分配组织的数据");
      //   return;
      // }

      this.$refs.distributeOrg.show();
    },

    toDistributeOrg(val) {
      if (val) {
        updateDeptId({ ids: this.ids, deptId: val }).then((res) => {
          if (res && res.code === 200) {
            this.$GlobalSuccessMessage("分配成功");
            this.getList();
          } else {
            this.$GlobalErrorConfirm("分配失败", res.msg);
          }
        });
      } else {
        this.$GlobalErrorConfirm("分配失败", "请选择组织");
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
